package javacommon.util;

import java.util.Vector;

public class StringUtils {
	public static boolean notNull(String s) {

		boolean rtn = s != null && s.trim().length() > 0 && !"".equals(s)
				&& !"null".equals(s);

		return SystemUseLimit.getBoolean(rtn);
	}

	public static boolean equals(String objstr, String bjstr) {

		boolean lean = false;
		lean = objstr != null && objstr.equals(bjstr);

		return SystemUseLimit.getBoolean(lean);
	}

	public static String[] split(String str, String type) {

		int begin = 0;
		int pos = 0;
		String tempstr = "";
		String array[] = (String[]) null;
		Vector vec = null;
		if (!notNull(str))
			return null;
		int len = str.trim().length();
		str = str + type;
		if (len > 0)
			for (; str.length() > 0; vec.add(tempstr)) {
				if (vec == null)
					vec = new Vector();
				pos = str.indexOf(type, begin);
				tempstr = str.substring(begin, pos);
				str = str.substring(pos + 1, str.length());
			}

		if (vec != null) {
			array = new String[vec.size()];
			for (int i = 0; i < vec.size(); i++)
				array[i] = (String) vec.get(i);

		}

		return array;
	}

	public static String len(String s, int len) {

		if (!notNull(s))
			s = "";

		int length = len - s.length();
		for (int i = 0; i < length; i++)
			s = "0" + s;

		return SystemUseLimit.getString(s);
	}

	public static String replace(String source, char str1, String str2) {
		return replace(source, String.valueOf(str1), str2);
	}

	public static String replace(String source, String str1, String str2) {
		if (source == null)
			return "";
		String desc = "";
		int posstart = 0;
		int posend = source.indexOf(str1, 0);
		int len;
		for (len = source.length(); posend >= 0 && posstart < len; posend = source
				.indexOf(str1, posstart)) {
			desc = desc + source.substring(posstart, posend) + str2;
			posstart = posend + str1.length();
		}

		if (posstart < len)
			desc = desc + source.substring(posstart, len);

		return SystemUseLimit.getString(desc);
	}
}
